package com.efruit.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.efruit.externalInterfaces.IProductInfoMag;
import com.efruit.struts.form.AddProductInfoForm;

public class AddProductInfoAction extends Action{
	
	IProductInfoMag productInfoMag = null;
	
	public IProductInfoMag getProductInfoMag() {
		return productInfoMag;
	}

	public void setProductInfoMag(IProductInfoMag productInfoMag) {
		System.out.println("setProductInfoMag");
		this.productInfoMag = productInfoMag;
	}

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		AddProductInfoForm addForm = (AddProductInfoForm)form;
		System.out.println(addForm.getName());
		System.out.println(addForm.getUrl());
		System.out.println(addForm.getPrice());
		System.out.println(addForm.getCount());
		try {
			System.out.println(productInfoMag+"------");
			productInfoMag.add(addForm.getName(),addForm.getUrl(),
					addForm.getPrice(), addForm.getCount() );
			
			addForm.clear();
			return mapping.findForward("addProductInfo");
		} catch (Exception e) {
			e.printStackTrace();
			return mapping.findForward("error");
		}
	}
}
